package com.zzl.finance.data.controller;

import java.util.Arrays;
import java.util.Map;

import com.zzl.apidoc.annotation.ApidocController;
import com.zzl.apidoc.annotation.ApidocOperation;
import com.zzl.apidoc.annotation.ApidocParam;
import com.zzl.general.common.apidoc.annotation.ApidocParamsPage;
import com.zzl.general.common.apidoc.annotation.ApidocResultKeyValR;
import com.zzl.general.common.apidoc.annotation.ApidocReturnPage;
import com.zzl.general.common.apidoc.annotation.ApidocReturnR;
import com.zzl.general.common.apidoc.constants.ResultTypeInR;
import com.zzl.general.common.ctrl.WebBaseCtrl;
import com.zzl.general.common.utils.LogUtils;
import com.zzl.general.common.utils.PageUtils;
import com.zzl.general.common.utils.Result;
import com.zzl.general.common.exception.SysException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import lombok.extern.slf4j.Slf4j;

import com.zzl.finance.data.entity.InstitutyDataEntity;
import com.zzl.finance.data.dto.InstitutyDataAddDto;
import com.zzl.finance.data.dto.InstitutyDataUpdateDto;
import com.zzl.finance.data.service.InstitutyDataService;
/**
 * 金融机构资料关系表
 *
 * @author gull
 * @date 2022-07-01 18:23:10
 */
@ApidocController("金融机构资料关系表")
@RestController
@SuppressWarnings("javadoc")
        @RequestMapping("data/institutydata")
    @Slf4j
public class InstitutyDataController extends WebBaseCtrl {
    @SuppressWarnings("all")
    @Autowired
    private InstitutyDataService institutyDataService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @ApidocOperation(description = "分页查询金融机构资料关系表数据", operationId = "data/institutydata" + "/list")
    @ApidocReturnPage(genericTypeClass = InstitutyDataEntity.class)
    public Result list(@ApidocParamsPage(name = "params") @RequestParam Map<String, Object> params) {
        PageUtils page = institutyDataService.queryPage(params);
        return Result.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    @ApidocOperation(description = "通过id获取金融机构资料关系表数据", operationId = "data/institutydata" + "/info/{id}")
    @ApidocReturnR(otherkv = {
            @ApidocResultKeyValR(resultType = ResultTypeInR.TYPE_OBJECT, key = "institutyData", valueClass = InstitutyDataEntity.class)
    })
    public Result info(@ApidocParam(description = "金融机构资料关系表id", name = "id", required = true) @PathVariable("id") String id) {
            InstitutyDataEntity institutyData = institutyDataService.getById(id);
        return Result.ok().put("data", institutyData);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @ApidocOperation(description = "保存金融机构资料关系表", operationId = "data/institutydata" + "/save")
    @ApidocReturnR
    public Result save(@ApidocParam(description = "保存的金融机构资料关系表对象值", name = "{institutyData}", required = true) @RequestBody InstitutyDataAddDto institutyData) {
        try {
                institutyDataService.saveInstitutyData(institutyData, this.getUser());
            return Result.ok();
        } catch (SysException e) {
            LogUtils.logSysException(log, e);
            return Result.error(e.getMsg());
        }
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    @ApidocOperation(description = "修改金融机构资料关系表", operationId = "data/institutydata" + "/update")
    @ApidocReturnR
    public Result update(@ApidocParam(description = "修改的金融机构资料关系表对象值", name = "institutyData", required = true) @RequestBody InstitutyDataUpdateDto institutyData) {
        try {
                institutyDataService.updateInstitutyDataById(institutyData, this.getUser());
            return Result.ok();
        } catch (SysException e) {
            LogUtils.logSysException(log, e);
            return Result.error(e.getMsg());
        }
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    @ApidocOperation(description = "删除金融机构资料关系表", operationId = "data/institutydata" + "/delete")
    @ApidocReturnR
    public Result delete(@ApidocParam(description = "删除的金融机构资料关系表对象id集合", name = "ids", required = true) @RequestBody String[] ids) {
            institutyDataService.removeByIds(Arrays.asList(ids));
        return Result.ok();
    }

}
